package org.sipsl.gisystems.gentest;
 
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;

import org.sipsl.gisystems.gentest.rte.commands.DisplayCounter;
import org.sipsl.gisystems.gentest.rte.commands.DisplaySub;
import org.sipsl.gisystems.gentest.rte.commands.ExpectedCounter;
import org.sipsl.gisystems.gentest.rte.commands.ExpectedSub;
import org.sipsl.gisystems.gentest.rte.commands.ResetAccount;
import org.sipsl.gisystems.gentest.rte.commands.ResetCalls;
import org.sipsl.gisystems.gentest.rte.commands.ResetCounter;
import org.sipsl.gisystems.gentest.rte.commands.RteCommand;
import org.sipsl.gisystems.gentest.rte.commands.SetBalance;
import org.sipsl.gisystems.gentest.rte.commands.SetBundle;
import org.sipsl.gisystems.gentest.rte.commands.SetMoVoice;
import org.sipsl.gisystems.gentest.rte.commands.UnSetBundle;
import org.sipsl.gisystems.gentest.rte.util.BucketLogic;
import org.sipsl.gisystems.gentest.rte.util.ExItem;
import org.sipsl.gisystems.gentest.rte.util.GenericUtil;
import org.sipsl.gisystems.gentest.rte.util.RteException;
import org.sipsl.gisystems.gentest.rte.util.VoiceMoParams;
import org.sipsl.gisystems.rte.V2.TestsuiteV2;
import org.sipsl.gisystems.rte.V2.TestsuiteV2.SubscriberType;
import org.sipsl.gisystems.rte.V2.TestsuiteV2.VoiceBatchGroup.Called;
import org.sipsl.gisystems.rte.V2.TestsuiteV2.VoiceBatchGroup.Caller;
import org.sipsl.gisystems.rte.V2.TestsuiteV2.VoiceBatchGroup.Duration;
import org.sipsl.gisystems.rte.V2.TestsuiteV2.VoiceBatchGroup.Duration.Result;
import org.sipsl.gisystems.rte.V2.TestsuiteV2.VoiceBatchGroup.Zone.VoiceBatch;
import org.sipsl.gisystems.rte.V2.TestsuiteV2.VoiceBatchGroup.Zone.VoiceBatch.VoiceBundle;

import com.rits.cloning.Cloner;

public class RteVoiceMoTestUnit {

	private ArrayList<RteCommand> testInstructions;
	private VoiceMoParams voiceParams;
	private double spent;
	ArrayList<VoiceBundle> Bundles;
	
	ArrayList<String> TestDescription;

	public RteVoiceMoTestUnit(
			TestsuiteV2 bix,
			TestsuiteV2 surepay,
			VoiceMoParams dp,
			Caller aParty,
			Called bParty,
			org.sipsl.gisystems.rte.V2.TestsuiteV2.VoiceBatchGroup.Zone.VoiceBatch batch,
			int index, List<Duration> durationList,
			SubscriberType subscriberType, int callingZone, Cloner cloner) {

		try {
			int ShowMe = 0;
			testInstructions = new ArrayList<RteCommand>();

			voiceParams = dp;

			int SubType = 0;

			if (subscriberType != null) {
				SubType = (subscriberType.getType().compareTo("PostPaid") == 0) ? 1
						: 0;
				if (subscriberType.getResetAccount() != null) {
					testInstructions.add(new ResetAccount(voiceParams,
							subscriberType.getResetAccount().getTemplate()));
				}
				if (subscriberType.getResetCounter() != null) {
					for (org.sipsl.gisystems.rte.V2.TestsuiteV2.SubscriberType.ResetCounter s : subscriberType
							.getResetCounter()) {
						testInstructions.add(new ResetCounter(voiceParams, s
								.getTemplate()));
					}
				}
			}

			testInstructions.add(new ResetCalls(voiceParams));
			testInstructions.add(new SetBalance(SubType, voiceParams));

			// int calcCounterPosition = 1;
			if (batch.getNewBundleLogic() == null
					|| (batch.getNewBundleLogic() != null && batch
							.getNewBundleLogic().toUpperCase().compareTo("YES") == 0)) {

				Bundles = new ArrayList<VoiceBundle>();

				Queue<BucketLogic> BucketQueue = new LinkedList<BucketLogic>();

				for (VoiceBundle bv2 : batch.getVoiceBundle()) {

					// bundle: apply = null -> subscribe only
					// bundle: apply = yes -> subscribe and check bucket used
					// /limit applied/ counter increased
					// bundle: apply = no -> subscribe and check not used
					// counter / limit not applied / counter unchanged

					// load from surepay.xml if referenced
					if (bv2.getReference() != null) {
						VoiceBundle tbd;
						tbd = getBundleFromSurepay(surepay, bv2.getReference(),
								cloner);
						// TODO position!!
						if (bv2.getApply() == null) {

						} else {
							tbd.setApply(bv2.getApply().toUpperCase());
							// parse and copy position "bucket,limit,counter
							String position[] = new String[3];
							position = bv2.getPositions().split(",");

							if (bv2.getStartDate() != null) {
								tbd.setStartDate(bv2.getStartDate());
							}
							if (bv2.getEndDate() != null) {
								tbd.setEndDate(bv2.getEndDate());
							}
							if (bv2.getStartTime() != null) {
								tbd.setStartTime(bv2.getStartTime());
							}
							if (bv2.getEndTime() != null) {
								tbd.setEndTime(bv2.getEndTime());
							}

							if (tbd.getVoiceBundleBucket() != null) {
								tbd.getVoiceBundleBucket().setPosition(
										new Integer(position[0]));
							}
							if (tbd.getVoiceBundleCounter() != null) {
								tbd.getVoiceBundleCounter().setPosition(
										new Integer(position[1]));
							}
							if (tbd.getVoiceBundleUBD() != null && position[2] != null) {
								tbd.getVoiceBundleUBD().setPosition(new Integer(position[2]));
							}

						}
						Bundles.add(tbd);
					} else {
						// limit
						Bundles.add(bv2);
					}
				}
				ExItem<Integer> bundleLimit = new ExItem<Integer>();
				ExItem<Integer> counterPosition = new ExItem<Integer>();
				ExItem<Integer> _discountPosition = new ExItem<Integer>();

				;
				for (VoiceBundle bundle : Bundles) {
					testInstructions.add(new SetBundle(voiceParams, bundle
							.getId(), GenericUtil.parseDate(GenericUtil
							.nullToEmpty(bundle.getStartDate())), GenericUtil
							.parseDate(GenericUtil.nullToEmpty(bundle
									.getEndDate())), GenericUtil
							.parseTime(GenericUtil.nullToEmpty(bundle
									.getStartTime())), GenericUtil
							.parseTime(GenericUtil.nullToEmpty(bundle
									.getEndTime()))));
					// get limit if exists
					if (bundle.getVoiceBundleLimit() != null) {
						if (bundle.getApply() != null) {
							bundleLimit.setValue(bundle.getVoiceBundleLimit()
									.getSize());
							if (bundle.getApply().toUpperCase()
									.compareTo("YES") != 0) {
								bundleLimit.unSet2();
							}
						}
					}
					// get bucket if exists
					if (bundle.getVoiceBundleBucket() != null) {
						BucketQueue.add(new BucketLogic(bundle
								.getVoiceBundleBucket().getSize(), 0,
								bundle.getApply().toUpperCase()
										.compareTo("YES") == 0, bundle
										.getVoiceBundleBucket().getPosition(),
								bundle));
					}
					// get counter if exists
					if (bundle.getVoiceBundleCounter() != null) {
						if (bundle.getApply() != null) {
							counterPosition.setValue(bundle
									.getVoiceBundleCounter().getPosition());
							if (bundle.getApply().toUpperCase()
									.compareTo("YES") != 0) {
								counterPosition.unSet2();
							}
						}
					}
					if (bundle.getVoiceBundleUBD() != null) {
						if (bundle.getApply().toUpperCase().compareTo("YES") == 0) {
							_discountPosition.setValue(bundle
									.getVoiceBundleUBD().getPosition());
						} else if (bundle.getApply().toUpperCase()
								.compareTo("YES") != 0) {
							_discountPosition.setValue(bundle
									.getVoiceBundleUBD().getPosition());
							_discountPosition.unSet2();
						}
					}

				}
				// Make call

				// TODO
				// the limit is set before sending the call???
				int amountToCall = durationList.get(index - 4).getTime();
				if (bundleLimit.isValid2()
						&& amountToCall >= bundleLimit.getValue()) {
					amountToCall = bundleLimit.getValue();
				} else {
					// nada
				}

				testInstructions.add(new SetMoVoice(dp, amountToCall,
						callingZone));

				// display
				testInstructions.add(new DisplaySub(voiceParams));
				if (GenTest.enqRteOption(bix, "USE_DISPLAY_COUNTER1")) {
					testInstructions.add(new DisplayCounter(1, voiceParams));
				}
				if (GenTest.enqRteOption(bix, "USE_DISPLAY_COUNTER2")) {
					testInstructions.add(new DisplayCounter(2, voiceParams));
				}

				// more buckets
				// take the first bucket
				// if apply
				// use it
				// if amountToCall > bucket
				// issue ExpectCounter(val=0)
				// amountToCall = amountToCall - bucket
				// else
				// issue ExpectCounter(bucket-amounToCall)
				// amounToCall = 0
				// excessToPay = amounToCall;
				//
				ExItem<Integer> excessToPay = new ExItem<Integer>();
				Map<VoiceBundle, Boolean> IsEmpty = new HashMap<VoiceBundle, Boolean>();

				amountToCall = upDurationToMultipleOfSlice(amountToCall, batch
						.getVoiceTariff().get(0).getSlice().intValue());
//				//ExItem<Integer> callDuration = new ExItem<Integer>();
//				callDuration.setValue(amountToCall);

				while (!BucketQueue.isEmpty()) {
					BucketLogic bulo = BucketQueue.remove();
					if (bulo.isApply()) {
						if (amountToCall >= bulo.getBucketSize()) {
							bulo.setBucketLeft(0);
							amountToCall = amountToCall - bulo.getBucketSize();
							testInstructions.add(new ExpectedCounter(bulo
									.getBucketLeft(), bulo.getPosition(),
									voiceParams));
							IsEmpty.put(bulo.getVoiceBundle(),
									new Boolean(true));
						} else { // amountToCall < bucket
							bulo.setBucketLeft(bulo.getBucketSize()
									- amountToCall);
							amountToCall = 0;
							testInstructions.add(new ExpectedCounter(bulo
									.getBucketLeft(), bulo.getPosition(),
									voiceParams));
							IsEmpty.put(bulo.getVoiceBundle(), new Boolean(
									false));
						}
					} else {// apply - no
						testInstructions.add(new ExpectedCounter(bulo
								.getBucketSize(), bulo.getPosition(),
								voiceParams));

					}
				}
				if (amountToCall > 0) {
					excessToPay.setValue(amountToCall);
				}

				if (counterPosition.isValid() && counterPosition.isValid2()) {
					testInstructions.add(new ExpectedCounter(amountToCall
							, counterPosition.getValue(),
							voiceParams));
				} else if (counterPosition.isValid()
						&& !counterPosition.isValid2()) {
					testInstructions.add(new ExpectedCounter(0, counterPosition
							.getValue(), voiceParams));
				}
				

				// calculate payment
				ExItem<Long> resultToPay = new ExItem<Long>();
				// check if predefined spending
				for (TestsuiteV2.VoiceBatchGroup.Duration.Result r : durationList
						.get(index - 4).getResult()) {
					if (r.getBandLabel().compareTo(batch.getId()) == 0) {
						if (r.getValue() != null) {
							GenericUtil.LOG("speding "
									+ r.getValue().intValue(), ShowMe, 0);
							resultToPay
									.setValue((long) r.getValue().intValue());
							break;
						}
					}
				}
				spent = 0;
				if (resultToPay.isValid()) {
					spent = resultToPay.getValue();
				} else {
					spent = getSpending(batch, durationList.get(index - 4),
							excessToPay);
				}
				
				if (_discountPosition.isValid() && _discountPosition.isValid2()) {
					testInstructions.add(new ExpectedCounter((int)spent
							, _discountPosition.getValue(),
							voiceParams));
				} else if (_discountPosition.isValid()
						&& !_discountPosition.isValid2()) {
					testInstructions.add(new ExpectedCounter(0, _discountPosition
							.getValue(), voiceParams));
				}
				
				if (SubType == 0) {
					int bal = (int) (Integer.parseInt(voiceParams.getBALANCE()
							.replace(".", "") + "000") - spent);
					testInstructions.add((new ExpectedSub(bal, SubType,
							voiceParams)));
				} else if (SubType == 1) {
					testInstructions.add((new ExpectedSub((int) (spent),
							SubType, voiceParams)));
				}

				for (VoiceBundle bundle : Bundles) {
					if (bundle.getDeleteOnExhaust() != null
							&& bundle.getDeleteOnExhaust().toUpperCase()
									.compareTo("YES") == 0
							&& IsEmpty.get(bundle)!=null) {
						// skip deletion
					} else {
						testInstructions.add(new UnSetBundle(voiceParams,
								bundle.getId()));
					}
				}

				// /////////////////////////////////////////////////////////////////////
			} else {
				GenericUtil.LOG("Must use newBundleLogic", 1, 0);
				System.exit(0);
			}
		} catch (RteException e) {
			e.printStackTrace();
			System.exit(0);
		}

	}

	public int getSpending(
			org.sipsl.gisystems.rte.V2.TestsuiteV2.VoiceBatchGroup.Zone.VoiceBatch blTariff,
			Duration durationCmpx, ExItem<Integer> duration)
			throws RteException {
		// TODO Auto-generated method stub

		int ShowMe = 0;
		GenericUtil.LOG("duration " + duration, ShowMe, 0);
		for (Result r : durationCmpx.getResult()) {
			if (r.getValue() != null) {
				if (r.getBandLabel().compareTo(blTariff.getId()) == 0) {
					GenericUtil.LOG(r.getValue(), ShowMe, 0);
					return r.getValue();
				}
			}
		}
		if (duration.isValid()
				&& duration.getValue() > blTariff.getVoiceTariff().get(0)
						.getMin()) {

			double a = (double) duration.getValue();
			int gra = (int) Math.ceil(a
					/ blTariff.getVoiceTariff().get(0).getSlice().intValue());
			double c = gra
					* blTariff.getVoiceTariff().get(0).getPrice().doubleValue();
			double b = c
					* blTariff.getVoiceTariff().get(0).getPrice().doubleValue();
			double d = c * 100;

			double dd = d * 100;
			int ddd = (int) dd;
			double dddd = ((double) ddd) / 100;

			double e = Math.ceil(dddd);
			double f = e * 1000;
			int g = (int) f;

			if (blTariff.getVoiceTariff().get(0).getStep() != null) {
				double s = blTariff.getVoiceTariff().get(0).getStep()
						.doubleValue() * 1000;
				g = g + (int) s;
			}
			if (blTariff.getVoiceTariff().get(0).getOutOfBundleFee() != null) {
				GenericUtil.LOG("outOfBundleFee "
						+ blTariff.getVoiceTariff().get(0).getOutOfBundleFee()
								.doubleValue(), ShowMe, 0);
				double s = blTariff.getVoiceTariff().get(0).getOutOfBundleFee()
						.doubleValue() * 1000 * 100;
				g = g + (int) s;
			}
			GenericUtil.LOG("a " + a, ShowMe, 0);
			GenericUtil.LOG("b " + b, ShowMe, 0);
			GenericUtil.LOG("gra " + gra, ShowMe, 0);
			GenericUtil.LOG("c " + c, ShowMe, 0);
			GenericUtil.LOG("d " + d, ShowMe, 0);
			GenericUtil.LOG("dd " + dd, ShowMe, 0);
			GenericUtil.LOG("ddd " + ddd, ShowMe, 0);
			GenericUtil.LOG("dddd " + dddd, ShowMe, 0);

			GenericUtil.LOG("e " + e, ShowMe, 0);
			GenericUtil.LOG("f " + f, ShowMe, 0);
			GenericUtil.LOG("g " + g, ShowMe, 0);

			return g;

		} else {
			double a;
			if (!duration.isValid()) {
				// to avoid minimal charge when outOfBundle is set
				a = 0;
			} else {
				a = (double) blTariff.getVoiceTariff().get(0).getMin()
						.intValue();
			}
			double b = a
					/ blTariff.getVoiceTariff().get(0).getSlice().intValue();
			double c = b
					* blTariff.getVoiceTariff().get(0).getPrice().doubleValue();
			double d = c * 100;
			double dd = d * 100;
			int ddd = (int) dd;
			double dddd = ((double) ddd) / 100;

			double e = Math.ceil(dddd);
			double f = e * 1000;
			int g = (int) f;

			if (blTariff.getVoiceTariff().get(0).getStep() != null) {
				double s = blTariff.getVoiceTariff().get(0).getStep()
						.doubleValue() * 1000;
				g = g + (int) s;
			}
			if (blTariff.getVoiceTariff().get(0).getOutOfBundleFee() != null) {
				GenericUtil.LOG("outOfBundleFee "
						+ blTariff.getVoiceTariff().get(0).getOutOfBundleFee()
								.doubleValue(), ShowMe, 0);
				double s = blTariff.getVoiceTariff().get(0).getOutOfBundleFee()
						.doubleValue() * 1000 * 100;
				g = g + (int) s;
			}
			GenericUtil.LOG("a " + a, ShowMe, 0);
			GenericUtil.LOG("b " + b, ShowMe, 0);
			GenericUtil.LOG("c " + c, ShowMe, 0);
			GenericUtil.LOG("d " + d, ShowMe, 0);
			GenericUtil.LOG("dd " + dd, ShowMe, 0);
			GenericUtil.LOG("ddd " + ddd, ShowMe, 0);
			GenericUtil.LOG("dddd " + dddd, ShowMe, 0);

			GenericUtil.LOG("e " + e, ShowMe, 0);
			GenericUtil.LOG("f " + f, ShowMe, 0);
			GenericUtil.LOG("g " + g, ShowMe, 0);

			return g;

		}

	}

	public void generateTest(String title) {
		int i = 0;
		(new File(title)).mkdir();
		for (RteCommand s : testInstructions) {
			s.dumpScript(title, i++);
		}
	}
	public String generateTestDocument() {
		int i = 0;
		String test = "";
		for (RteCommand s : testInstructions) {
			if (s.getTestDescription().length() > 0)
				test = test + "\n" + s.getTestDescription();
		}
		return test;
	}


	private VoiceBundle getBundleFromSurepay(TestsuiteV2 surepay,
			String reference, Cloner cloner) {

		for (VoiceBatch db : surepay.getVoiceBatchGroup().getZone().get(0)
				.getVoiceBatch()) {
			if (db.getVoiceBundle().size() == 0) {
				continue;
			}
			if (db.getVoiceBundle().get(0).getReference().compareTo(reference) == 0) {
				VoiceBundle vbd = (VoiceBundle) cloner.deepClone(db
						.getVoiceBundle().get(0));
				return vbd;
			}
		}
		return null;
	}

	public static int upDurationToMultipleOfSlice(int duration, int slice) {

		int ShowMe = 0;
		GenericUtil.LOG("duration " + duration, ShowMe, 0);
		GenericUtil.LOG("slice " + slice, ShowMe, 0);

		double a = (double) duration;
		double bb = a / slice;
		// need to round b to granularity
		return (int) Math.ceil(bb) * slice;
	}

	public void generateDocVoice2(int testNumber, String testSuiteName,
			String testName, Caller A_id, Called B_id, Integer time,
			String callingZone) {
		// //BRS ID : test number
		// //Subject : Topic of test : <testsuiteV2 id="TestVoiceV3">
		// //Test Name : Name of test : testName
		// //Test Objective :Verify that... call costs...
		// //Step Name (Design Steps) : subscribe to, make a call from a to b of
		// tot secs
		// //Description (Design Steps) things to verify (ama etc...)

		int ShowMe = 0;

		testNumber++;

		String TEST = new String();

		GenericUtil.LOG("BRS ID " + testNumber, ShowMe, 0);
		TEST = "" + testNumber + ",";
		GenericUtil.LOG("Subject " + testSuiteName, ShowMe, 0);
		TEST = TEST + testSuiteName + ",";
		GenericUtil.LOG("Test Name " + testName, ShowMe, 0);
		TEST = TEST + testName + ",";
		GenericUtil.LOG("Test Objective: ", ShowMe, 1);
		GenericUtil.LOG("Verify that a call from the " + callingZone
				+ " network ", ShowMe, 1);
		TEST = TEST + "Verify that a call from the " + callingZone
				+ " network ";
		GenericUtil.LOG("of " + time + " seconds ", ShowMe, 1);
		TEST = TEST + "of " + time + " seconds ";
		GenericUtil
				.LOG("from " + A_id.getMsisdnA().toString() + " ", ShowMe, 1);
		TEST = TEST + "from " + A_id.getMsisdnA().toString() + " ";
		GenericUtil.LOG("to " + B_id.getMsisdnB().toString() + " ", ShowMe, 1);
		TEST = TEST + "to " + B_id.getMsisdnB().toString() + " ";

		if (!Bundles.isEmpty()) {
			GenericUtil.LOG("uses bucket", ShowMe, 1);
			TEST = TEST + "uses bucket";
			if ((int) spent != 0) {
				GenericUtil.LOG(" and is charged " + spent + " units.", ShowMe,
						1);
				TEST = TEST + " and is charged " + spent + " units.";
			} else {
				GenericUtil.LOG(".", ShowMe, 1);
				TEST = TEST + ".";
			}
		} else {
			if ((int) spent != 0) {
				GenericUtil.LOG("costs " + (int) spent + " units.", ShowMe, 1);
				TEST = TEST + "costs " + (int) spent + " units.";
			} else {
				GenericUtil.LOG("is free.", ShowMe, 1);
				TEST = TEST + "is free.";
			}
		}
		TEST = TEST + ",";
		GenericUtil.LOG("", ShowMe, 0);
		GenericUtil.LOG("Step Name: ", ShowMe, 1);
		if (!Bundles.isEmpty()) {
			GenericUtil.LOG("Subscribe to bundle ", ShowMe, 1);
			TEST = TEST + "Subscribe to bundle ";
			for (int k = 0; k < Bundles.size(); k++) {
				TEST = TEST + Bundles.get(k).getId();
				GenericUtil.LOG(Bundles.get(k).getId(), ShowMe, 1);
			}
			GenericUtil.LOG("", ShowMe, 0);
			TEST = TEST + ". ";
		}
		GenericUtil.LOG("Make a call from " + callingZone + " network ",
				ShowMe, 1);
		TEST = TEST + "Make a call from " + callingZone + " network ";
		GenericUtil.LOG("of " + time + " seconds ", ShowMe, 1);
		TEST = TEST + "of " + time + " seconds ";
		GenericUtil
				.LOG("from " + A_id.getMsisdnA().toString() + " ", ShowMe, 1);
		TEST = TEST + "from " + A_id.getMsisdnA().toString() + " ";
		GenericUtil
				.LOG("(imsi " + A_id.getImsiA().toString() + ") ", ShowMe, 1);
		TEST = TEST + "(imsi " + A_id.getImsiA().toString() + ") ";
		GenericUtil.LOG("to " + B_id.getMsisdnB().toString() + " ", ShowMe, 1);
		TEST = TEST + "to " + B_id.getMsisdnB().toString() + " ";
		if (B_id.getImsiB().toString().length() > 0) {
			GenericUtil.LOG("(imsi " + B_id.getImsiB().toString() + " )",
					ShowMe, 1);
			TEST = TEST + "(imsi " + B_id.getImsiB().toString() + " )";
		}

		GenericUtil.LOG("", ShowMe, 0);
		TEST = TEST + "";

		GenericUtil.LOG("", ShowMe, 0);
		GenericUtil.LOG("", ShowMe, 0);
		GenericUtil.LOG(TEST, ShowMe, 0);
		FileWriter fstream;
		try {
			fstream = new FileWriter(testSuiteName + ".csv", false);
			BufferedWriter out = new BufferedWriter(fstream);
			out.write(TEST + "\n");
			out.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void generateDocVoice(int testNumber, String testSuiteName,
			String testName, String callingZone, boolean isNew) {
		// //BRS ID : test number
		// //Subject : Topic of test : <testsuiteV2 id="TestVoiceV3">
		// //Test Name : Name of test : testName
		// //Test Objective :Verify that... call costs...
		// //Step Name (Design Steps) : subscribe to, make a call from a to b of
		// tot secs
		// //Description (Design Steps) things to verify (ama etc...)

		int ShowMe = 0;

		testNumber++;

		String TEST = new String();

		GenericUtil.LOG("BRS ID " + testNumber, ShowMe, 0);
		TEST = "" + testNumber + ",";
		GenericUtil.LOG("Subject " + testSuiteName, ShowMe, 0);
		TEST = TEST + testSuiteName + ",";
		GenericUtil.LOG("Test Name " + testName, ShowMe, 0);
		TEST = TEST + testName + ",";
		
		//////
		
		TEST = TEST + "Originating Zone " +callingZone + generateTestDocument();
		FileWriter fstream;
		try {
			fstream = new FileWriter(testSuiteName + ".csv", isNew);
			BufferedWriter out = new BufferedWriter(fstream);
			out.write(TEST + "\n");
			out.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public RteVoiceMoTestUnit() {
		// for testing purposes
	}

}
